using System.Collections;
using System.Collections.Generic;
using Spine;
using Spine.Unity;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SpineTouchConfigSO))]
public class SpineTouchConfigSOInspector : Editor
{
    public override void OnInspectorGUI()
    {
        SpineTouchConfigSO so = target as SpineTouchConfigSO;
        so.skeletonData = EditorGUILayout.ObjectField(
            "Spine资源",
            so.skeletonData,
            typeof(SkeletonDataAsset),
            false) as SkeletonDataAsset;
        
        if (so.skeletonData != null)
        {
            bool skeletonDataChanged = !string.IsNullOrEmpty(so.lastEditSkeletonData) && so.skeletonData != null && so.lastEditSkeletonData != so.skeletonData.name;
            if (skeletonDataChanged)
            {
                EditorGUILayout.HelpBox($"Spine资源和上一次编辑的记录不一样,上一次的资源：{so.lastEditSkeletonData}", MessageType.Error);
            }

            if (GUILayout.Button("打开编辑器"))
            {
                if (skeletonDataChanged)
                {
                    if (EditorUtility.DisplayDialog("警告", 
                            $"当前的Spine资源和上一次编辑的资源不一样，确定继续吗？\n上一次编辑的Spine资源{so.lastEditSkeletonData}",
                            "确定",
                            "取消"))
                    {
                        SpineTouchConfigSOEditor.ShowWindow(so);
                    }
                }
                else
                {
                    SpineTouchConfigSOEditor.ShowWindow(so);
                }
            }
        }
        else
        {
            EditorGUILayout.HelpBox("请先选择一个Spine资源", MessageType.Info);
        }
    }
}
